{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "17377597",
   "metadata": {},
   "source": [
    "- 2023/03\n",
    "- 本周主要内容：图像识别（人脸识别）"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ab4f0c65",
   "metadata": {},
   "source": [
    "# 重点:"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d0d34792",
   "metadata": {},
   "source": [
    "#### 1.API文档阅读（考试）"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "dc82e9a5",
   "metadata": {},
   "source": [
    "#### 2.requests模块（考试）"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d3459ddc",
   "metadata": {},
   "source": [
    "#### 3.百度通用图像识别"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d47e010f",
   "metadata": {},
   "source": [
    "# 本周内容："
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c7db730c",
   "metadata": {},
   "source": [
    "# 一、人脸识别概念和基础"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "fb85fec3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'request_id': '1679734223,b9dfea35-4ffa-427d-8d8c-6d60e89c4a5c', 'time_used': 170, 'faces': [{'face_token': 'b223168d46e4da1513b98ff87415247b', 'face_rectangle': {'top': 99, 'left': 185, 'width': 110, 'height': 110}, 'attributes': {'gender': {'value': 'Male'}, 'age': {'value': 27}, 'smile': {'value': 0.171, 'threshold': 50.0}, 'headpose': {'pitch_angle': 15.077997, 'roll_angle': -4.8415275, 'yaw_angle': -16.418198}, 'blur': {'blurness': {'value': 0.564, 'threshold': 50.0}, 'motionblur': {'value': 0.564, 'threshold': 50.0}, 'gaussianblur': {'value': 0.564, 'threshold': 50.0}}, 'emotion': {'anger': 33.073, 'disgust': 0.001, 'fear': 0.001, 'happiness': 2.126, 'neutral': 64.783, 'sadness': 0.001, 'surprise': 0.015}, 'facequality': {'value': 30.903, 'threshold': 70.1}, 'beauty': {'male_score': 77.484, 'female_score': 78.491}}}], 'image_id': '2TpPSLI2H40fpa5gZkW0Gg==', 'face_num': 1}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "Face++ 人脸检测\n",
    "'''\n",
    "\n",
    "request_url = \"https://api-cn.faceplusplus.com/facepp/v3/detect\" # face++的人脸识别的url\n",
    "# 二进制方式打开图片文件\n",
    "# 1.图片文件准备\n",
    "f = open('xuezhiqian.jpg', 'rb') # 图片格式jpg，照片和笔记要放在同一个文件夹里\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "# 2. 酬载准备\n",
    "payload = {\n",
    "    'api_key':'jRpCaZ34kqNYJ8Zppdc-yGGum_YkETov', # 这些要改，api要改的，用自己的api\n",
    "    'api_secret':'Vr0PtRCw-ZFwYXTKVfi6aDNaSqlfunK3',\n",
    "    'image_base64':img, # 在face++找文档\n",
    "    'return_attributes':'gender,age,smiling,headpose,facequality,emotion,blur,beauty'\n",
    "}\n",
    "\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data = payload, headers=headers)\n",
    "if response:\n",
    "    print (response.json())\n",
    "else:\n",
    "    print(response.status_code)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "664ac85f",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "645065f6",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1439afaa",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2ed75ab9",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "63fd0d26",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "13b77191",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9c8d9f66",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5dd2bf12",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9722669e",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1f6c059c",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1dca0449",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "008a2ddb",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d97d83b8",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0b31f88a",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cb672865",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
